package edu.calvin.djs32.cs214.interpreters.prettyprinter;

import org.antlr.runtime.tree.Tree;

public class PrettyPrinter {

	public Object computeSpan(int i) {
		return "<span class=\"" + computeCssClass(i) + "\">" + i + "</span>";
	}

	private String computeCssClass(int i) {
		return ((i >= 0) ? "integer" : "integer negative");
	}

	public Object interpret(Tree tree) {
		int type = tree.getType();
		switch (type) {
		case 4: return "<pre>" + computeSpan(Integer.decode((tree.getText()))) + "</pre>";
		case 5: return "<pre>" + computeSpan(tree.getText()) + "<pre>";
		default: throw new IllegalStateException("Type not supported!");
		}
	}

	public Object computeSpan(String string) {
		int stringLength = string.length();
		string = string.substring(1,stringLength-1);
		return "<span class=\"string\">&lsquo;" + string + "&rsquo;</span>";
	}

}
